let Vue

class Store {
  constructor(options) {
    this.$options = options

    this._getters = options.getters

    const computed = {}
    this.getters = {}
    const store = this

    Object.keys(this._getters).forEach(item => {
      const fn = this._getters[item]

      computed[item] = function() {
        return fn(store.state)
      }

      Object.defineProperty(store.getters, item, {
        get: () => {
          return store.state[item]
        }
      })
    })

    this.state = new Vue({
      data: options.state,
      computed
    })

    console.log(2346, this.state, this.getters, this)

    this.commit = this.commit.bind(this)
    this.dispatch = this.dispatch.bind(this)
  }
  commit(type, info) {
    this.$options.mutations[type](this.state, info)
  }
  dispatch(type, info) {
    this.$options.actions[type](this, info)
  }
}

function install(_Vue) {
  Vue = _Vue

  Vue.mixin({
    beforeCreate() {
      if(this.$options.store) {
        console.log('this.$options.store',this.$options.store )
        Vue.prototype.$store = this.$options.store
      }
     
    }
  })
}

export default {
  Store,
  install
}